import { createRoot } from "react-dom/client";
import { Spin } from "antd";
import * as React from "react";

export function Loading() {
  const showLoading = (name) => {
    const dom = document.createElement("div");
    dom.setAttribute("id", "axios-loading");
    document.body.appendChild(dom);
    const root = createRoot(dom);
    root.render(<Spin spinning={true} fullscreen tip={name || "页面加载中"}></Spin>);
  };
  const hideLoading = () => {
    const loadingName = document.getElementById("axios-loading");
    if (loadingName) {
      document.body.removeChild(loadingName);
    }
  };
  return {
    showLoading,
    hideLoading,
  };
}

export default Loading;
